
import java.sql.*;

public class Demo10  {
    public static void main(String[] args) {
        Connection connection=null;
        Statement statement=null;
        try {
            DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
            String url = "jdbc:mysql://localhost:3306/demo?serverTimezone=GMT&useSSL=false&characterEncoding=utf-8";
            String user = "root";
            String password = "1015";
            connection= DriverManager.getConnection(url, user, password);
            statement= connection.createStatement();
            String sql = "update demo set name='李四' where id=1";
            int row = statement.executeUpdate(sql);
            System.out.println("影响了数据库" + row + "条数据");
            statement.close();
            connection.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally{
            try{
                if(statement !=null){
                    statement.close();
                }
            }catch(SQLException e){
                throw new RuntimeException(e);
            }
            try{
                if(connection !=null){
                    connection.close();
                }
            }catch(SQLException e){
                throw new RuntimeException();
            }
        }

    }
}


